package com.dbgs.insurance.insuredperson.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.dbgs.insurance.insuredperson.R;

public class NewsInfoAdapter extends BaseAdapter{
    private Context mContext;
    private LayoutInflater inflater;
    private static final int ITEM_VIEW_TYPE_WITH_VIDEO = 0;
    private static final int ITEM_VIEW_TYPE_WITH_ONE_IMAGE_NO_INTRODUCE = 1;
    private static final int ITEM_VIEW_TYPE_WITH_ONE_IMAGE_AND_INTRODUCE = 2;
    private static final int ITEM_VIEW_TYPE_WITH_THREE_IMAGE_NO_INTRODUCE = 3;

    public NewsInfoAdapter(Context context) {
        this.mContext = context;
        inflater = LayoutInflater.from(context.getApplicationContext());
    }

    @Override
    public int getCount() {
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 4;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        switch (getItemViewType(i)){
            case ITEM_VIEW_TYPE_WITH_VIDEO:


                 return view;
            case ITEM_VIEW_TYPE_WITH_ONE_IMAGE_NO_INTRODUCE:
                if (view==null || view.getId()!=ITEM_VIEW_TYPE_WITH_ONE_IMAGE_NO_INTRODUCE){
                    view = inflater.inflate(R.layout.news_item_one_image_with_introduce,null);
                    view.setId(ITEM_VIEW_TYPE_WITH_ONE_IMAGE_NO_INTRODUCE);

                    viewHolder=new ViewHolder();
                    viewHolder.rlNewsItem=(RelativeLayout) view.findViewById(R.id.rl_news_item);
                    viewHolder.imageViewNews=(ImageView) view.findViewById(R.id.news_img);
                    viewHolder.title=(TextView) view.findViewById(R.id.title);
                    viewHolder.updateTime=(TextView) view.findViewById(R.id.update_time);

                    view.setTag(viewHolder);
                }else {
                    viewHolder=(ViewHolder) view.getTag();
                }

                return view;
            case ITEM_VIEW_TYPE_WITH_ONE_IMAGE_AND_INTRODUCE:
                if (view==null || view.getId()!=ITEM_VIEW_TYPE_WITH_ONE_IMAGE_AND_INTRODUCE){
                    view = inflater.inflate(R.layout.news_item_one_image_with_introduce,null);
                    view.setId(ITEM_VIEW_TYPE_WITH_ONE_IMAGE_AND_INTRODUCE);

                    viewHolder=new ViewHolder();
                    viewHolder.rlNewsItem=(RelativeLayout) view.findViewById(R.id.rl_news_item);
                    viewHolder.imageViewNews=(ImageView) view.findViewById(R.id.news_img);
                    viewHolder.title=(TextView) view.findViewById(R.id.title);
                    viewHolder.body=(TextView) view.findViewById(R.id.body);
                    viewHolder.updateTime=(TextView) view.findViewById(R.id.update_time);

                    view.setTag(viewHolder);
                }else {
                    viewHolder=(ViewHolder) view.getTag();
                }
                return view;
            case ITEM_VIEW_TYPE_WITH_THREE_IMAGE_NO_INTRODUCE:
                if (view==null || view.getId()!=ITEM_VIEW_TYPE_WITH_THREE_IMAGE_NO_INTRODUCE){
                    view = inflater.inflate(R.layout.news_item_one_image_with_introduce,null);
                    view.setId(ITEM_VIEW_TYPE_WITH_THREE_IMAGE_NO_INTRODUCE);

                    viewHolder=new ViewHolder();
                    viewHolder.rlNewsItem=(RelativeLayout) view.findViewById(R.id.rl_news_item);
                    viewHolder.imageView1=(ImageView) view.findViewById(R.id.news_img1);
                    viewHolder.imageView2=(ImageView) view.findViewById(R.id.news_img2);
                    viewHolder.imageView3=(ImageView) view.findViewById(R.id.news_img3);
                    viewHolder.title=(TextView) view.findViewById(R.id.title);
                    viewHolder.updateTime=(TextView) view.findViewById(R.id.update_time);

                    view.setTag(viewHolder);
                }else {
                    viewHolder=(ViewHolder) view.getTag();
                }

                return view;
            default:
                throw new IllegalArgumentException();
        }
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    private class ViewHolder{
        RelativeLayout rlNewsItem;
        ImageView imageViewNews,imageView1,imageView2,imageView3;
        TextView title;
        TextView body;
        TextView updateTime;
    }
}
